package com.ibeeking.found.file.rest.service.office.documentserver.callbacks.implementations;

import com.ibeeking.found.file.rest.service.office.documentserver.callbacks.Callback;
import com.ibeeking.found.file.rest.service.office.documentserver.callbacks.Status;
import com.ibeeking.found.file.rest.service.office.documentserver.managers.callback.CallbackManager;
import com.ibeeking.found.file.rest.service.office.dto.Track;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class ForcesaveCallback implements Callback {
    @Resource
    private CallbackManager callbackManager;

    @Override
    public int handle(Track body, String fileName) {  // handle the callback when the force saving request is performed
        int result = 0;
        try {
            callbackManager.processForceSave(body, fileName);  // file force saving process
        } catch (Exception ex) {
            ex.printStackTrace();
            result = 1;
        }
        return result;
    }

    @Override
    public int getStatus() {  // get document status
        return Status.MUST_FORCE_SAVE.getCode();  // return status 6 - document is being edited, but the current document state is saved
    }
}
